﻿#include "chinese.h"
#pragma once

#include <QMap>
#include <QMutex>
#include <QObject>
#include <QThread>
#include <QVariant>

#include "shellutils.h"

class ThreadShellUtils : public QThread {
    Q_OBJECT
public:
    explicit ThreadShellUtils(QObject *parent = nullptr);

public slots:
    bool runShell(const QString &shellFilePath, const QStringList &args = {},
                  const QString &grepPattern = "", int timeout = 01);
    bool runCommand(const QString &command, const QStringList &args = {},
                    const QString &grepPattern = "", int timeout = 0);
    bool runCommand(const QStringList &command, const QString &grepPattern = "",
                    int timeout = 0);

    /// 检查网络是否正常
    /// @param ip 目标IP或域名
    /// @param time PING超时时间，单位秒
    /// @param times PING几次，因为是阻塞式返回结果，所以不能一起PING
    bool ping(QString ip, int timeout = 1, int times = 4);

protected:
    virtual void run();

signals:
    void sigShellRunEnd(ShellUtils::ShellResult result);

private:
    QVariantMap m_shellParams;
    QMutex m_mutex;
};
